using System;
using System.Collections.Generic;
using System.Text;
using ALib;

namespace TradingPlatform
{
    public class OrderInfo
    {
        private readonly double _price;

        public double Price
        {
            get { return _price; }
        }
        private readonly double _quantity;

        public double Quantity
        {
            get { return _quantity; }
        }

        private bool _cancelled;

        public bool Cancelled
        {
            get { return _cancelled; }
            set { _cancelled = value; }
        }

        private double _remaining;

        public double Remaining
        {
            get
            {
                return _remaining;
            }
            set
            {
                GoodValue.Assert(_quantity * value >= 0);
                GoodValue.Assert(Math.Abs(value) <= Math.Abs(_remaining) && Math.Abs(_remaining) <= Math.Abs(_quantity));
                _remaining = value;
            }
        }

        public bool Alive
        {
            get
            {
                bool result = !_cancelled && Remaining != 0;
                return result;
            }
        }

        public double TotalFilled
        {
            get
            {
                double result = _quantity - _remaining;
                return result;
            }
        }

        public OrderInfo(double price,double quantity)
        {
            GoodValue.Assert(price > 0 || double.IsNaN(price));
            GoodValue.AssertDouble(quantity);

            _price = price;
            _quantity = quantity;
            _remaining = quantity;
            _cancelled = false;
        }

        public override string ToString()
        {
            string result = double.IsNaN(_price) ? string.Format(@"MarketOrder,{0},{1}", _price, _remaining) : string.Format(@"LimitOrder,{0},{1}", _price, _remaining);
            return result;
        }
    }
}
